Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Convert JS Objects to ES6 Maps and vice versa.
ES6 Map
objects are really nice for iteration, but they're not so nice for
directly referencing properties, the way JS Objects are. This is a nice way to
convert back and forth. First, simply use npm
to include es6-mapify
in your
project's dependencies:
npm install -S es6-mapify
Now you can import it and use it like so:
import { mapify } from 'es6-mapify';
// converts basic objects
let myObj = {foo: 'bar'};
let myMap = mapify(myObj);
myMap.get('foo'); // 'bar'
// doesn't do anything to non-objects
mapify('foo'); // 'foo';
mapify(null); // null
// is smart about objects nested inside arrays and other objects
let arrMap = mapify([1, {foo: 'bar'}, 3]);
arrMap[2]; // 3
arrMap[1].get('foo'); // 'bar'
let myMap = mapify({foo: {bar: 'baz'}});
myMap.get('foo').get('bar'); // 'baz';
Of course, you might want to go the other direction too! If you have a Map
and want the corresponding basic JS object, just use demapify
:
import { demapify } from 'mapify';
// converts basic maps
let myMap = new Map();
myMap.set('foo', 'bar');
demapify(myMap); // {foo: 'bar'}
// doesn't do anything to non-objects
demapify(2); // 2
// is smart about nested Maps (and Maps in arrays)
let myMap = new Map()
, myMap2 = new Map();
myMap.set('foo', 'bar');
myMap2.set('baz', 'quux');
myMap.set('inception', myMap2);
demapify(myMap); // {foo: 'bar', inception: {baz: 'quux'}}
FAQs
Convert JS objects to ES6 Maps and vice versa
The npm package es6-mapify receives a total of 21,150 weekly downloads. As such, es6-mapify popularity was classified as popular.
We found that es6-mapify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.